import { Component, Injector, ViewChild, Input } from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { Paginator } from 'primeng/components/paginator/paginator';
import { Table } from 'primeng/components/table/table';

import { WorkflowServiceProxy, UserServiceProxy, ExecutionPointerDto, OutsourcingWorkFlowServiceProxy, SupplierQuotationServiceProxy, SupplierQuotationModel } from '@shared/service-proxies/service-proxies';
import { finalize } from 'rxjs/operators';
import * as _ from 'lodash';
import * as moment from 'moment';
import { from } from 'rxjs';

@Component({
    selector: 'app-flowApprovalRecord',
    templateUrl: './FlowApprovalRecord.component.html',
    styleUrls: ['./FlowApprovalRecord.component.css']
})
export class FlowApprovalRecordComponent extends AppComponentBase {

    @Input() workflowid: any;
    constructor(injector: Injector,
        private _supplierquotationService: SupplierQuotationServiceProxy,
        private _workflowService: WorkflowServiceProxy,
        private _userServiceProxy: UserServiceProxy, ) { super(injector); }

    ngOnInit() {
        this.initForm();
    }

    initForm() {
        this._workflowService.getExecutionPointer(this.workflowid).subscribe(dto => {
            this.primengTableHelper.totalRecordsCount = dto.length;
            this.primengTableHelper.records = dto;
            this.primengTableHelper.hideLoadingIndicator();
            _.forEach(dto, viewItem => {
                this._userServiceProxy.getUserInfo(viewItem.extensionAttributes.ActionUser)
                    .subscribe(userResult => {
                        viewItem.auditUserName = userResult.surname + userResult.name + '(' + userResult.userName + ')';
                    });
            });
        });

    }
    getAuditName(item: ExecutionPointerDto) {
        return item.extensionAttributes.Prompt;
    }
}
